/**
 * 查看源码
 */
window.wangEditor.showSourceCode = {
    // editor create之后调用
    init: function(editorSelector,editor){
        editor.txt.text(editor.txt.html());
        console.log(editor.txt);
        var _html = '<div class="w-e-menu"><a class="_wangEditor_btn_showSourceCode" href="###">html</a></div>';
        $(editorSelector + " .w-e-toolbar").append(_html);
        $(editorSelector + ' ._wangEditor_btn_showSourceCode').on('click',function () {
            var _this = $(this);
            if(_this.text() === 'html'){
                editor.txt.html('<script type="text/html" style="display:block">' + editor.txt.html() );
                _this.text('contents');
            }else{
                editor.txt.html(window.wangEditor.showSourceCode.replaceScript(editor.txt.html()));
                _this.text('html');
            }
        });
    },
    replaceScript:function (str) {
        var _text = str.replace('<script type="text/html" style="display:block">','');
        if(_text.substr(_text.length - 9,9) === '</script>'){
            _text = _text.substr(0,_text.length - 9);
        }
        return _text;
    }
};